// #include"cpp-httplib/httplib.h"
// //默认路径
// const std::string root_path="./wwwroot";

// int main()
// {
//     httplib::Server svr;
//     svr.set_base_dir(root_path.c_str());
//     //指定路径"/hi"
//     svr.Get("/hi",[](const httplib::Request &req, httplib::Response &rsp){
//         rsp.set_content("你好,世界!","text/plain; charset=utf-8");
//     });
//     svr.listen("0.0.0.0",8888);//服务器是否打开对应端口
//     return 0;
// }

#include"searcher.hpp"
#include"cpp-httplib/httplib.h"

const std::string root_path="./wwwroot";
const std::string input="./data/raw_html/raw.txt";

int main()
{
    ns_searcher::Searcher search;
    search.InitSearcher(input);

    httplib::Server svr;
    svr.set_base_dir(root_path.c_str());

    svr.Get("/s",[&search](const httplib::Request &req, httplib::Response &rsp){
        if(!req.has_param("word"))
        {
            rsp.set_content("必须要有关键字","text/plain; charset=utf-8");
            return;
        }
        std::string word = req.get_param_value("word");
        std::cout<<"用户在搜索"<<word<<std::endl;
        std::string json_string;
        search.Search(word,&json_string);
        rsp.set_content(json_string,"application/json");
    });
    svr.listen("0.0.0.0",8888);//服务器是否打开对应端口
    return 0;
}